/*
 * @Author: your name
 * @Date: 2021-08-30 12:04:25
 * @LastEditTime: 2021-08-30 12:22:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day06\6-排序.js
 */

//1.函数的功能：正序、倒序  排序依据：默认是ASII
//2.参数 不传参。默认排序
//3.返回值
//4.影响到了原数组
var arr1 = [3, 4, 6, 7, 2];
var result = arr1.sort();
console.log(result);
console.log(arr1.sort()); //直接console.log(arr1);

var arr2 = [10, 1, 23, 2];
arr2.sort();
console.log(arr2); //1,10,2,23  ASII排序 对于数据量大的数据没有意义

//reverse 反向排序
console.log(arr1.reverse()); //7,6,4,3,2
console.log(arr2.reverse()); //23,2,10,1

//自定义排序法 函数作为参数
function compare(v1, v2) {
    //大于0 小于0 等于0
    return v1 - v2;

}
arr2.sort(compare); //冒泡排序，快速排序，插入排序
console.log(arr2); //1,2,10,23